package com.java.collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class ArrayListTests {
    static void doRemove1(){
        List<String> list=new ArrayList<>();
        list.add("A");
        list.add("B");
        list.add("C");
        //不允许采用如下方式,在迭代的同时执行删除操作
        for(String s:list){
            list.remove(s);//ConcurrentModificationException
        }
        System.out.println(list);
    }
    static void doRemove2(){
        List<String> list=new ArrayList<>();
        list.add("A");
        list.add("B");
        list.add("C");
        Iterator<String> iterator = list.iterator();
        while(iterator.hasNext()){
             iterator.next();//需要先执行next,移动指针获取元素
             iterator.remove();
        }
        System.out.println(list);
    }
    static void doRemove3(){
        List<String> strings = Arrays.asList("A", "B", "C");
        strings.clear();//UnsupportedOperationExceptio
    }
    public static void main(String[] args) {
        //doRemove2();
        doRemove3();
    }
}
